/*
 * constraint.cpp
 *
 *      Author: Jerome RD Soine and Christoph A Brand
 *      Institution: Schwarz goup, Institute for Theoretical Physics, Heidelberg University, Germany
 */

#include "../../../../../include/base/cell_models/ACM/constraints/constraint.h"

double Constraint::getSumOfScalarProductsOfGradientsOverAllVertices(Constraint * c1, Constraint * c2){
	vector<Vertex*> vertices = *c1->getGeomObject()->getVertices();
	double ret=0;
	for(unsigned int i=0;i<vertices.size();i++){
		if(!vertices[i]->isFixed()){
			Vertex grad1 = c1->getGradient(*vertices[i]);
			Vertex grad2 = c2->getGradient(*vertices[i]);
			ret += grad1*grad2;
		}
	}
	return ret;
}

double Constraint::getSumOfScalarProductsOfGradientsAndForcesOverAllVertices(vector<double> & forces){
	vector<Vertex*> vertices = *g->getVertices();
	double ret=0;
	for(unsigned int i=0;i<vertices.size();i++){
		if(!vertices[i]->isFixed()){
			Vertex grad = getGradient(*vertices[i]);
			Vertex force(forces[3*i+0],forces[3*i+1],forces[3*i+2]);
			ret += grad*force;
		}
	}
	return ret;

}

